package client

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import server.MapleStatEffect

import java.util.concurrent.ScheduledFuture

class MapleBuffStatValueHolder @JsonCreator
constructor(
        @JsonProperty("cid") val cid: Int,
        @JsonProperty("localDuration") var localDuration: Int,
        @JsonProperty("startTime") val startTime: Long,
        @JsonProperty("endTime") val endTime: Long,
        @JsonProperty("value") var value: Int,
        @JsonProperty("effect") val effect: MapleStatEffect,
        @JsonProperty("schedule") var schedule: ScheduledFuture<*>?,
        @JsonProperty("z") var z: Int) {



    var effectID = effect.sourceid
    var x = effect.x
    var mode = 0

    val buffLength: Int
        get() =
            if (localDuration < 2100000000) {
                (localDuration.toLong() - (System.currentTimeMillis() - this.startTime)).toInt()
            } else {
                2100000000
            }

    fun cancel() {
        if (schedule != null) {
            schedule!!.cancel(true)
            schedule = null
        }
    }
}
